import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

class AndroidLoginR{
String accountType;
String Email;
String Passwd;
String Service;


public AndroidLoginR(String Em, String pwd)
{
	this.Email = Em;
	this.Passwd = pwd;
}


public String clientDetails() throws UnsupportedEncodingException, ClientProtocolException, IOException
{

		String authToken = null;
		
		
		HttpClient client = new DefaultHttpClient();
		String postURL = "https://www.google.com/accounts/ClientLogin";
		HttpPost post = new HttpPost(postURL);
		System.out.println("Post is "+post.toString());
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		nvps.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE"));
		nvps.add(new BasicNameValuePair("Email",this.Email));
		nvps.add(new BasicNameValuePair("Passwd", this.Passwd));
		nvps.add(new BasicNameValuePair("Service","writely"));
		
		UrlEncodedFormEntity uent = new UrlEncodedFormEntity(nvps,HTTP.UTF_8);
		System.out.println("URL encoded entity "+ uent.toString());
		post.setEntity(uent);
		HttpResponse response = client.execute(post);
		System.out.println("Response is "+ response.toString());
		
		
		HttpEntity hent = response.getEntity();
		System.out.println("Http Response Entity "+hent);
		if(hent != null)
		{
			authToken = EntityUtils.toString(hent);
			System.out.println("authToken = "+ authToken);
		}
		return authToken;
}

}